package com.internetCafes.spms.web.certificate.service.impl;

import com.internetCafes.spms.core.generic.GenericDao;
import com.internetCafes.spms.core.generic.GenericServiceImpl;
import com.internetCafes.spms.core.model.pageModel.DataGrid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.internetCafes.spms.web.certificate.dao.CertificateRenewalInfoMapper;
import com.internetCafes.spms.web.certificate.entity.CertificateRenewalInfo;
import com.internetCafes.spms.web.certificate.service.CertificateRenewalInfoService;


/**
 * 证书延期信息 CertificateRenewalInfoService 实现类
 *
 * @author Sunny
 */
@Service("certificateRenewalInfoService")
public class CertificateRenewalInfoServiceImpl extends GenericServiceImpl<CertificateRenewalInfo, Long> implements CertificateRenewalInfoService {

    @Autowired
    private CertificateRenewalInfoMapper certificateRenewalInfoMapper;

    @Override
    public Boolean deleteByCertificateId(Long certificateId) {
        return certificateRenewalInfoMapper.deleteByCertificateId(certificateId) > 0;
    }

    @Override
    public List<CertificateRenewalInfo> query(Map<String, Object> params) {
        return certificateRenewalInfoMapper.selectByParams(params);
    }

    @Override
    public CertificateRenewalInfo findById(Long id) {
        return certificateRenewalInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CertificateRenewalInfo> queryByIds(List<Long> ids) {
        Map<String, Object> params = new HashMap<>();
        params.put("ids", ids);
        return certificateRenewalInfoMapper.selectByParams(params);
    }

    @Override
    public List<CertificateRenewalInfo> page(Map<String, Object> params, int page, int rows) {
        params.put("page", page);
        params.put("rows", rows);
        return certificateRenewalInfoMapper.selectByParams(params);
    }

    @Override
    public long count(Map<String, Object> params) {
        return certificateRenewalInfoMapper.countByParams(params);
    }

    @Override
    public CertificateRenewalInfo findFirst(Map<String, Object> params) {
        List<CertificateRenewalInfo> list = certificateRenewalInfoMapper.selectByParams(params);
        CertificateRenewalInfo certificateRenewalInfo =null;
        if (list != null && list.size() > 0) {
            certificateRenewalInfo =list.get(0);
        }
        return certificateRenewalInfo;
    }

    @Override
    public int save(CertificateRenewalInfo certificateRenewalInfo) {
        return certificateRenewalInfoMapper.insert(certificateRenewalInfo);
    }

    @Override
    public int saveBatch(List<CertificateRenewalInfo> certificateRenewalInfoList) {
        return certificateRenewalInfoMapper.insertBatch(certificateRenewalInfoList);
    }

    @Override
    public int saveSelective(CertificateRenewalInfo certificateRenewalInfo) {
        return certificateRenewalInfoMapper.insertSelective(certificateRenewalInfo);
    }

    @Override
    public int update(CertificateRenewalInfo certificateRenewalInfo) {
        return certificateRenewalInfoMapper.updateByPrimaryKey(certificateRenewalInfo);
    }

    @Override
    public int updateSelective(CertificateRenewalInfo certificateRenewalInfo) {
        return certificateRenewalInfoMapper.updateByPrimaryKeySelective(certificateRenewalInfo);
    }

    @Override
    public int delete(Long id) {
        return certificateRenewalInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(List<Long> ids) {
        return certificateRenewalInfoMapper.deleteBatchByPrimaryKey(ids);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        if(ids != null && ids.length > 0){
            for(Long id : ids){
                delete(id);
            }
        }
    }

    @Override
    public GenericDao<CertificateRenewalInfo, Long> getDao() {
        return certificateRenewalInfoMapper;
    }

    /**
	 * DataGrid
	 */
    @Override
    public DataGrid dataGrid(Map<String, Object> params, int pageNo, int pageSize) {

        List<CertificateRenewalInfo> certificateRenewalInfoList = page(params, (pageNo - 1 < 0 ? -1 : pageNo - 1) * pageSize, pageSize);
        long count = count(params);

        return new DataGrid(certificateRenewalInfoList, count, pageSize, pageNo);
    }
}